package com.gufe.controller.admin.mmp;

import com.gufe.dto.MilitaryShowDTO;
import com.gufe.entity.MilitaryShow;
import com.gufe.result.Result;
import com.gufe.service.admin.mmp.MilitaryTrainService;
import com.gufe.vo.MilitaryShowVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/admin/mp")
public class MilitaryTrainController {
    @Autowired
    private MilitaryTrainService militaryTrainService;

    // 获取军事训练展示信息
    @GetMapping("/military-train")
    @Cacheable(cacheNames = "trainInfoCache",key = "'getTrainInfo'")
    public Result getTrainInfo() {
        log.info("获取军训展示信息...");
        List<MilitaryShowVO> militaryShowS = militaryTrainService.getTrainInfo();
        return Result.success(militaryShowS);
    }

    // 根据ID获取军事训练展示信息
    @GetMapping("/military-train/{id}")
    @Cacheable(cacheNames = "trainInfoCache",key = "'getTrainInfo:id=' + #id")
    public Result getTrainInfoById(@PathVariable Integer id) {
        log.info("根据ID获取军训展示信息...");
        MilitaryShowVO militaryShow = militaryTrainService.getTrainInfoById(id);
        return Result.success(militaryShow);
    }

    // 新建军事训练展示信息
    @PostMapping("/military-train")
    @CacheEvict(cacheNames = "trainInfoCache",allEntries = true) // 清除所有军训展示缓存
    public Result addTrainInfo(@RequestBody MilitaryShowDTO militaryShowDTO) {
        log.info("新建军训展示信息:{}...",militaryShowDTO);
        militaryTrainService.addTrainInfo(militaryShowDTO);
        return Result.success();
    }

    // 更新军训展示信息
    @PutMapping("/military-train")
    @CacheEvict(cacheNames = "trainInfoCache",allEntries = true) // 清除所有军训展示缓存
    public Result updateTrainInfo(@RequestBody MilitaryShowDTO militaryShowDTO) {
        log.info("更新军训展示信息...");
        militaryTrainService.updateTrainInfo(militaryShowDTO);
        return Result.success();
    }

    // 根据ID删除军事训练展示信息
    @DeleteMapping("/military-train/{id}")
    @CacheEvict(cacheNames = "trainInfoCache",allEntries = true) // 清除所有军训展示缓存
    public Result deleteTrainInfo(@PathVariable Integer id) {
        log.info("根据ID:{}删除军训展示信息...",id);
        militaryTrainService.deleteTrainInfo(id);
        return Result.success();
    }



}
